<?php
/**
*ajax 数据交互操作
*/
class ajaxControl extends skymvc{
	public $oc_where;
	public function __construct(){
		parent::__construct();			
	}
	
	public function onInit(){
		$this->oc_where=M("login")->userid?" (userid=".M("login")->userid." or oc_ssid='".OC_SSID."') ":"oc_ssid='".OC_SSID."' ";	
	}
	
	public function onDefault(){
		
	}
	
	
	public function onGet(){
		$model=get('model','h');
		$fun=get('fun','h');
		$limit=get('limit','i');
		$this->goALl("接口权限不足",1);
		if($limit){
			$data=M($model)->$fun($limit);
		}else{
			$data=M($model)->$fun();
		}
	 
		
		if(get('ret')){
			$sdata[get('ret','h')]=$data;
		}else{
			$sdata=$data;
		}
		 
		if(empty($data)){
			C()->goALl("error",1); 
		}else{
			C()->goALl("success",0,$sdata); 
		}
	}
	
	public function onNewMsg(){
		$time=get('time','i');
		$now=time();
		$ct1=M("notice")->getCount("userid=".M("login")->userid." AND status=0 AND dateline>$time ");
		$ct2=M("sysmsg_user")->getCount("userid=".M("login")->userid." AND status=0 AND dateline>$time ");
		$this->sexit(json_encode(array(
			"sysmsg"=>intval($ct2),
			"notice"=>intval($ct1),
			"total"=>$ct1+$ct2,
			"time"=>$now
		)));
	}
	/*所有的通知*/
	public function onAllNotice(){
		$shopn=M("shop_notice")->getCount(" status=0 AND adminid=".intval($_SESSION['ssshopadmin']['adminid']));
		$ymdiann=M("ymdian_notice")->getCount(" status=0 AND adminid=".intval($_SESSION['ssymdianadmin']['adminid']));
		$koudain=M("koudai_notice")->getCount(" status=0 AND adminid=".intval($_SESSION['sskoudaiadmin']['adminid']));
		if($_SESSION['sskoudaiadmin']==2){
			$koudaidzn=$koudain;
			$koudain=0;
			
		}
		$kucunn=M("kucun_notice")->getCount(" status=0 AND adminid=".intval($_SESSION['sskucunadmin']['adminid']));
		$tgyuann=M("tgyuan_notice")->getCount(" status=0 AND adminid=".intval($_SESSION['sstgyuanadmin']['adminid']));
		//测试
		//$koudaidzn=$shopn=10;
		$data=array(
			"shopn"=>intval($shopn),
			"ymdiann"=>intval($ymdiann),
			"koudain"=>intval($koudain),
			"koudaidzn"=>intval($koudaidzn),
			"kucunn"=>intval($kucunn),
			"tgyuann"=>intval($tgyuann),
		);
		
		
		$this->goAll("success",0,$data);
	}
	
	public function onbotnav_cart_num(){
		
		$ymdian=M("ymdian_order_cart")->selectOne(array(
			"where"=>$this->oc_where ." AND siteid=".SITEID,
			"fields"=>" sum(amount) as ct"
		));
		
		$koudai=M("koudai_order_cart")->selectOne(array(
			"where"=>$this->oc_where ." AND siteid=".SITEID,
			"fields"=>" sum(amount) as ct"
		));
		
		$shop=M("shop_order_cart")->selectOne(array(
			"where"=>$this->oc_where ." AND siteid=".SITEID,
			"fields"=>" sum(amount) as ct"
		));
		$all=$ymdian+$koudai+$shop;
		echo intval($all);
		
	}
	
	
	/**
	* 区域操作  获取省市地区
	*/
	public function ondistrict(){
		$id=get('id','i');
		echo "<option value=0>请选择</option>";
		if($id){
			 
			$data=M("site_city")->id_title(array("where"=>"pid=$id","limit"=>10000));
			if($data){
				foreach($data as $k=>$v){
					echo "<option value=".$k.">".$v."</option>";
				}
			}
		}
		exit; 
	}
}

?>